package com.schoolcloud.serve.controller;

import com.schoolcloud.common.model.PageDTO;
import com.schoolcloud.common.model.R;
import com.schoolcloud.serve.dto.ItemRequestSaveDTO;
import com.schoolcloud.serve.entity.ItemRequests;
import com.schoolcloud.serve.entity.RequestProcess;
import com.schoolcloud.serve.query.ItemRequestQuery;
import com.schoolcloud.serve.service.ItemRequestsService;
import com.schoolcloud.serve.service.LostFoundInteractionService;
import com.schoolcloud.serve.vo.ItemRequestInfoVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/serve/lost-found/item-request")
@RequiredArgsConstructor
public class ItemRequestController {
    private final ItemRequestsService itemRequestsService;
    private final LostFoundInteractionService lostFoundInteractionService;
    @GetMapping("/page")
    public R<PageDTO<ItemRequests>> getRequestPage(ItemRequestQuery query) {
        PageDTO<ItemRequests> page = itemRequestsService.getRequestPage(query);
        return R.ok(page);
    }

    @GetMapping("/{id}")
    public R<ItemRequests> getItemRequestById(@PathVariable Integer id) {
        ItemRequests itemRequests = itemRequestsService.getById(id);
        return R.ok(itemRequests);
    }   @GetMapping("/info/{id}")
    public R<ItemRequestInfoVO> getItemRequestInfoById(@PathVariable Integer id) {
        ItemRequestInfoVO itemRequests = lostFoundInteractionService.getItemRequestInfoById(id);
        return R.ok(itemRequests);
    }

    @PostMapping
    public R saveItemRequest(@RequestBody ItemRequestSaveDTO dto) {
        lostFoundInteractionService.saveItemRequest(dto);
        return R.ok();
    }
    @PostMapping("/process")
    public R requestProcess(@RequestBody RequestProcess requestProcess) {
        lostFoundInteractionService.requestProcess(requestProcess);
        return R.ok();
    }

    @PutMapping
    public R<ItemRequests> update(@RequestBody ItemRequests itemRequests) {
        itemRequestsService.updateById(itemRequests);
        return R.ok(itemRequests);
    }

    @DeleteMapping("/{id}")
    public R<String> delete(@PathVariable Integer id) {
        itemRequestsService.removeById(id);
        return R.ok("删除成功");
    }
}
